//
// Created by hsj on 2022/1/10.
//
#include <iostream>
#include "t_extern.h"
//使用其他文件的变量和函数
extern double warning;
extern void t_et(int a);
//const类似于static，只在当前文件使用: undefined reference to `const_not_extern'
//const 类似static，多个文件包含头文件时候，多个文件自己独享const变量，此时类似static
//extern int const_not_extern;

//但是如果要覆盖这种特殊的const行为变成共享， 1.cpp文件中：extern const int const_not_extern_out = 9988;
//                                      2.cpp文件中：extern const int const_not_extern_out;
extern const int const_not_extern_out;

//测试extern的变量和函数
void test_extern(){
    using namespace std;
    cout<<"globle warning is "<<warning<<endl;

    update(0.1);
    cout<<"globle warning is now "<<warning<<endl;

    local();
    cout<<"globle warning is final "<<warning<<endl;

    t_et(18);

//    const类似于static，只在当前文件使用: undefined reference to `const_not_extern'
//    const 类似static，多个文件包含头文件时候，多个文件自己独享const变量，此时类似static
//    cout<<"globle const_not_extern is "<<const_not_extern<<endl;

    cout<<"globle const_not_extern_out is "<<const_not_extern_out<<endl;
}

void update(double dt){
    using std::cout;
    using std::endl;
    extern double warning;
    warning += dt;

    cout<<"update globle warning to "<<warning<<endl;
}

void local(){
    using std::cout;
    using std::endl;
    double warning = 0.8;
    cout<<"local warning to "<<warning<<" but globle warning to "<< ::warning<<endl;//使用全局的warning
}
